package see.battle.gui;

import see.battle.Const;
import see.battle.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.DisplayMetrics;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class StartView extends SurfaceView implements SurfaceHolder.Callback {
  private Bitmap _image;
  private int _widthInPx;
  private int _heightInPx;
  
  public StartView(Context context, DisplayMetrics metrics) {
    super(context);
    getHolder().addCallback(this);
    setFocusable(true);
    _widthInPx = metrics.widthPixels;
    _heightInPx = metrics.heightPixels;
   _image = BitmapFactory.decodeResource(getResources(), 
        R.drawable.start);
  }
  
  public void onDraw(Canvas canvas) {
    canvas.drawBitmap(_image, 0, 0, null);
    Paint p = new Paint();
    p.setStrokeWidth(Const.welcomeTextStrokeWidth);
    p.setColor(Const.welcomeTextColor);
    p.setTextSize(Const.welcomeTextSize);
    p.setStyle(Paint.Style.FILL_AND_STROKE);
    p.setAntiAlias(true);
    canvas.drawText("Touch screen to continue...", 
       _widthInPx * Const.welcomeTextLeft, 
       _heightInPx * Const.welcomeTextTop, p);       
  }

  public void surfaceChanged(SurfaceHolder holder, int format, int width,
      int height) {
    // TODO Auto-generated method stub
    
  }

  public void surfaceCreated(SurfaceHolder holder) {
    Canvas c = null;
    try {          
      c = holder.lockCanvas(null);
      synchronized (holder) {
        onDraw(c);
      }
    } finally {
      if (c != null) {
        holder.unlockCanvasAndPost(c);
      }
    }
  }

  public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    
  }
}
